﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using System.Data.SqlClient;
using System.IO;

namespace PlanningDepartment
{
    public partial class FrMain : Telerik.WinControls.UI.RadForm
    {
        public FrMain()
        {
            InitializeComponent();
        }
        private void ChangeThemeName(Control control, string themeName)
        {
            IComponentTreeHandler radControl = control as IComponentTreeHandler;
            if (radControl != null) { radControl.ThemeName = themeName; }
            foreach (Control child in control.Controls)
            { ChangeThemeName(child, themeName); }
        }
        private void FrMain_Load(object sender, EventArgs e)
        {
            ChangeThemeName(this, "Office2010Blue");
            Disable();
            Mni_DangNhap_Click(null,null);
        }
        public void User(string Users)
        {
            lb_User.Text = Users;
        }
        private void Mni_DangNhap_Click(object sender, EventArgs e)
        {
            FrDangNhap FrDN = new FrDangNhap();
            FrDN.MdiParent = this;
            
            FrDN.Show();
        }
        /*private void FrMain_Load(object sender, EventArgs e)
        {
            Mni_DangNhap_Click(null, null);
            Disable();
        }*/
        private void Disable()
        {
            Mni_Department_.Visibility=ElementVisibility.Hidden;
        }

        private void Mni_Exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Mni_Planning_Click(object sender, EventArgs e)
        {
            FrPlanning Fr = new FrPlanning();
            Fr.MdiParent = this;
            Fr.Show();
            Fr.Users(lb_User.Text);
        }
        public void Enable(string Users)
        {
            Process prs = new Process();
            SqlConnection Conn = prs.Connect();
            SqlCommand cmd = new SqlCommand();
            try
            {
                Conn.Open();
                string check = @"select Area from dbo.Users where UsersName='" + Users + "'";
                cmd.Connection = Conn;
                cmd.CommandText = check;
                //MessageBox.Show(check);
                check = cmd.ExecuteScalar().ToString();
                if (check == "KHKH")
                {
                    Mni_Department_.Visibility = Telerik.WinControls.ElementVisibility.Visible;
                    Mni_Planning.Visibility = Telerik.WinControls.ElementVisibility.Visible;
                    Mni_Supplier.Visibility = ElementVisibility.Hidden;
                    
                }
                if (check == "CungTieu")
                {
                    Mni_Department_.Visibility = Telerik.WinControls.ElementVisibility.Visible;
                    Mni_Planning.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
                    Mni_Supplier.Visibility = ElementVisibility.Visible;
                }
                if (check == "administrator")
                {
                    Mni_Department_.Visibility = Telerik.WinControls.ElementVisibility.Visible;
                    Mni_Planning.Visibility = Telerik.WinControls.ElementVisibility.Visible;
                    Mni_Supplier.Visibility = ElementVisibility.Visible;
                }
                if (check == "KV5")
                {
                    Mni_Department_.Visibility = Telerik.WinControls.ElementVisibility.Visible;
                    Mni_Planning.Visibility = Telerik.WinControls.ElementVisibility.Visible;
                    Mni_Supplier.Visibility = ElementVisibility.Hidden;

                }
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Conn.Close();
                cmd.Dispose();
            }
            // Mni_KhoGo.Visible = true;
        }

        private void Mni_Supplier_Click(object sender, EventArgs e)
        {
            FrCungTieu Fr = new FrCungTieu();
            Fr.MdiParent = this;
            Fr.Show();
            Fr.Users(lb_User.Text);
        }

        private void Mni_ChangePass_Click(object sender, EventArgs e)
        {
            FrDoiMatKhau Fr = new FrDoiMatKhau();
            Fr.MdiParent = this;
            Fr.Show();
            //Fr.Users(lb_User.Text);
        }

        private void Mni_Login_Click(object sender, EventArgs e)
        {
            FrDangNhap Fr = new FrDangNhap();
            Fr.MdiParent = this;
            Fr.Show();
        }

        private void FrMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult TL;
            TL = MessageBox.Show("BẠN CÓ MUỐN THOÁT KHỎI CHƯƠNG TRÌNH KHÔNG ?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (TL == DialogResult.No)
            {
                e.Cancel = true;
            }
        }
        private void Mni_Logout_Click(object sender, EventArgs e)
        {
            foreach (Form mdiForm in this.MdiChildren)
                mdiForm.Close();
            Mni_Department_.Visibility = ElementVisibility.Hidden;
            Mni_Login_Click(null, null);
        }
        private void Mni_Help_Click(object sender, EventArgs e)
        {
            Process prs = new Process();
            prs.Open_Word2007("C:\\Huynh\\Trainning.docx");
        }

        private void FrMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            System.Diagnostics.Process.GetCurrentProcess().Kill();
            Application.Exit();
        }

        private void Mni_LinerOptimal_Click(object sender, EventArgs e)
        {
            linear_programming FrL = new linear_programming();
            FrL.MdiParent = this;
            FrL.Show();
        }

        private void Mni_NonLiner_Click(object sender, EventArgs e)
        {

        }

        private void Mni_NhapLieu_Click(object sender, EventArgs e)
        {
            FrNhapLieu fr = new FrNhapLieu();
            fr.Show();

        }

        
       
       
    }
}
